export default {
  name: 'MSelectBizQueryItem',
  props: {
    queryParam: Object,
    queryConfig: Array,
  },
  data() {
    return {}
  },
  methods: {
    renderQueryItem() {
      return this.queryConfig.map(queryItem => {
        const { key, label, placeholder, dictCode, props, customRender, mode, defaultValue } = queryItem
        const options = {
          props: {},
          on: {
            pressEnter: () => this.$emit('pressEnter'),
          }
        }
        if (props != null) {
          Object.assign(options.props, props)
        }
        if (placeholder === undefined) {
          if (dictCode) {
            options.props['placeholder'] = `请选择${label}`
          } else {
            options.props['placeholder'] = `请输入${label}`
          }
        } else {
          options.props['placeholder'] = placeholder
        }

        // 如果有传入defaultValue则设置默认值
        if (defaultValue != undefined) {
          options.props['value'] = defaultValue
          console.log('设置了', defaultValue, options.props)
        }

        let input
        if (typeof customRender === 'function') {
          input = customRender.call(this, { key, options, queryParam: this.queryParam })
        } else if (dictCode && !mode) {
          input = <j-dict-select-tag {...options} vModel={this.queryParam[key]} dictCode={dictCode} style="width:180px;" />
        } else if (dictCode && mode) {
          console.log(11, options)
          input = <j-multi-select-tag {...options} vModel={this.queryParam[key]} dictCode={dictCode} style="width:180px;" />
          console.log('input', input)
        } else {
          input = <a-input {...options} vModel={this.queryParam[key]} />
        }
        return <a-form-item key={key} label={label}>{input}</a-form-item>
      })
    },
  },
  render() {
    return <span>{this.renderQueryItem()}</span>
  },
}